/**
 * Copyright © 2014 Creativor Studio.
 * About license information, please see LICENSE.txt.
 */
package org.rayson.server.common.parser;

import org.rayson.api.annotation.NotNull;
import org.rayson.share.http.HttpContentType;

/**
 * An factory used to create {@link ParameterParser}s.
 * 
 * @author creativor
 */
public class ParameterParserFactory {
	private static ParameterParser formParameterParser = new FormParameterParser();

	/**
	 * Get default parser. Equals to {@link #getParser(HttpContentType)} of
	 * {@link HttpContentType#FORM_URLENCODED}.
	 */
	public static ParameterParser getParser() {
		return formParameterParser;
	}

	/**
	 * Find a parser by giving content type.
	 * 
	 * @throws RuntimeException
	 *             If no such parser found.
	 */
	public static ParameterParser getParser(
			@NotNull final HttpContentType contentType) throws RuntimeException {
		if (contentType == null)
			throw new IllegalArgumentException("contentType should not be null");
		switch (contentType) {
		case FORM_URLENCODED:
			return formParameterParser;

		default:
			break;
		}
		throw new RuntimeException("No such parser of content type "
				+ contentType);
	}

	private ParameterParserFactory() {
		// Forbidden.
	}
}